<?php

namespace app\api\controller\qsy;


use app\admin\controller\activity\Subject;
use app\admin\model\activity\ActivityType;
use app\admin\model\activity\ProjectActivity;
use app\admin\model\activity\SubjectActivity;
use app\admin\model\party\PartyBanner;
use app\admin\model\party\PartyType;
use app\admin\model\party\Party as PartyModel;
use app\admin\model\qsy\Banner;
use app\admin\model\qsy\Indexbanner;
use app\admin\model\qsy\Story;
use app\admin\model\spots\ScenicSpots;
use app\admin\model\wanlshop\Shop;
use app\common\controller\Api;
use app\common\handler\TimeHandler;
use app\common\helpers\ImageUtil;
use app\common\model\Config;
use think\Model;

/**
 * 吃喝玩乐
 */
class Party extends Api
{
    protected $noNeedLogin = ['*'];
    protected $noNeedRight = ['*'];


    //轮播列表
    public function bannerList()
    {
        $list = PartyBanner::field('id,img')->where('status','1')->order('create_time desc')->limit(6)->select();
        if($list){
            foreach ($list as $v){
                $v['img'] = ImageUtil::handle($v['img']);
            }
        }
        $this->success('获取成功', $list);
    }

    //类型
    public function TypeList()
    {
        $pidTypeList = (new PartyType)->field('id,name,icon')->where(['pid'=>0,'status'=>'1'])->select();
        if($pidTypeList){
            foreach ($pidTypeList as $v)  {
                $v['icon'] = ImageUtil::handle($v['icon']);
                $v['chlid'] = (new PartyType)->field('id,name,icon')->where(['status'=>'1','pid'=>$v['id']])->select();
            }
        }
        $this->success("获取成功",$pidTypeList);
    }

    //列表
    public function list()
    {
        $page = $this->request->param('page',1);//页码
        $pageSize = $this->request->param('pageSize',10);//每页展示数量
        $search = $this->request->param('search');//搜索

        $bigType = $this->request->param('big_type');//大类
        $smallType = $this->request->param('smallType');//小类
        $where = [
            'a.is_del'=> '0',
            'a.status'=> '1' ,
            's.status'=> 'normal',
        ];
        if($bigType){
            $where['big_type'] = $bigType;
        }
        if($smallType){
            $where['small_type'] = $smallType;
        }
        if($search){
            $where['title'] = ['like','%' .$search. '%'];
        }
        $model=(new PartyModel())->alias('a')
//            ->field('a.id,cover_img,shopname,title,price,address')
            ->field('a.id,cover_img,shopname,title,address')
            ->join('wanlshop_shop s','s.id = a.shop_id','left')
            ->where($where)
            ->order('create_time desc')
            ->paginate($pageSize, '', ['page' => $page, 'list_rows' => $pageSize]);
        $total= $model->total();
        $list =  $model->items();
        if($list){
            foreach ($list as $v){
                $v['cover_img'] = ImageUtil::handle($v['cover_img']);
            }
        }
        $result = array("total" =>$total , "list" => $list);
        $this->success("获取成功",$result);
    }


    //周边详情
    public function  partyDetails(){
        $id = $this->request->param('id');
        $info = (new PartyModel())                                 
                ->alias('p')
                ->join('wanlshop_shop s','s.id = p.shop_id','left')
//                ->field('p.id,title,label,cover_img,price,end_time,sold_num,phone,content,open_hours,open_weeks,address,lng,lat')
                ->field('p.id,title,label,cover_img,sold_num,phone,content,open_hours,open_weeks,address,lng,lat,shopname')
                ->where('p.id','=',$id)
               ->find();
        if($info){
            $site = \think\Config::get("site");
            $info['site_name'] = $site['site_name'];
            $info['open_weeks_arr'] = explode(',',$info['open_weeks']);
            $info['cover_img'] = ImageUtil::handle($info['cover_img']);
            $info['labelAll'] = !in_array($info['label'],["",null]) ? explode(',',$info['label']) : [];
            $this->success('获取成功', $info);
        }
        $this->error('不存在');
    }

}
